package exception;

import java.util.Scanner;

public class divide2 {
    public static void main(String[] agrs) {
        float a, b, c;
        System.out.println("请输入两个数：");//键盘输入的固定格式
        Scanner in = new Scanner(System.in);
        try {
            a = in.nextFloat();
            b = in.nextFloat();
            try {
                c = a / b;
                if (String.valueOf(c).equals("Infinity")){
                    throw new ArithmeticException();//抛出异常
                }
                System.out.println("商为：" + c);
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("除数不能为零");
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("只能输入数字");
        }
           System.out.println("程序结束");

    }
}
